const socketserver = require('socket.io');
const logger = require("../common/logger");
const url = require("url")
const socketioJwt = require("socketio-jwt");
const config = require('../config/config');
let Namespaces = {};
let io;
let Sockets = module.exports;

Sockets.init = (server) => {
    let SocketIO = require('socket.io');
    let socketioWildcard = require('socketio-wildcard')();
    io = new SocketIO(server, {
        serveClient: false,
        pingInterval: 10000,
        pingTimeout: 5000,
        cookie: true
    });
    io.use(socketioJwt.authorize({
        secret: config.TOKEN_SECRET,
        handshake: true
    }));
    io.use(socketioWildcard);
    io.on('connection', onConnection);
    Sockets.server = io;
};




function onConnection(socket) {
    console.log(socket)
};


// exports.createsocket = (a) => {
//     io = new socketserver(a, {
//         serveClient: false,
//         pingInterval: 10000,
//         pingTimeout: 5000,
//         cookie: true
//     }).listen(9000);
//     io.on("connection", (socket) => {
//         console.log("新的用户连接");
//         //console.log(socket.handshake.query);
//         socket.on("message", (msg) => {
//             console.log(msg)
//         })
//         socket.on('disconnect', (reason) => {
//             console.log(socket.id, 1)
//         });
//     });
// };
